package io.eyer.cluster.proxy;

import io.eyer.nio.core.event.Acceptor;
import io.eyer.registry.DefaultZookeeperClient;
import io.eyer.registry.ZooKeeperClient;
import io.eyer.rpc.proxy.ServerProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by Administrator on 2015/8/26.
 */
public class ZookeeperServerProxy extends ServerProxy {
    private static Logger logger = LoggerFactory.getLogger(ServerProxy.class);
    public static ConcurrentHashMap<Class<?>, Object> services = new ConcurrentHashMap<>();
    private ZooKeeperClient zooKeeperClient;

    public ZookeeperServerProxy(String host, int port, Acceptor acceptor, String zkUrl) throws IOException {
        super(host, port, acceptor);
        //name/host:port/service
        zooKeeperClient = new DefaultZookeeperClient(zkUrl);
        String format = "/eyer/" + URLEncoder.encode(String.format("rpc/%s:%s/Services", host, port),"UTF-8");
        zooKeeperClient.create(format, true);
    }


}
